package com.sve.Controller;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sve.Dao.StationMapper;
import com.sve.Entity.Station;

@Controller
@RequestMapping("Station")
public class StationController {
	private StationMapper stationservice;

	public StationMapper getStationservice() {
		return stationservice;
	}
	
	@Autowired
	public void setStationservice(StationMapper stationservice) {
		this.stationservice = stationservice;
	}
	
	@RequestMapping("indexs")
	public String indexs(Model model,String station,String time){
		List<Station> stationlist=stationservice.SelectStation();
		String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
		Calendar cal = Calendar.getInstance();
		int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if(week_index<0){
			week_index = 0;
		} 
		System.out.println(weeks[week_index]);
		model.addAttribute("weeks",weeks[week_index]);
		model.addAttribute("Stations",stationlist);
		model.addAttribute("Station",station);
		model.addAttribute("time",time);
		return "indexs";
	}
	
	@RequestMapping("index")
	public String index(Model model){
		List<Station> stationlist=stationservice.SelectStation();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//�������ڸ�ʽ
		
		model.addAttribute("Station",stationlist);
		model.addAttribute("DD",df.format(new Date()));
		
		return "index";
	}
}
